﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FCTC_Web.Models;
using FCTC_Web.DAL;
using DAL;
using FCTC_Web.Utilities;

namespace FCTC_Web.Controllers.Maintains
{
    [HandleError]
    
    public class ShopController : Controller
    {
        //[Authorize]
        public ViewResult Index(int? pageId)
        {
             return View("Index", Pager6.Ins.GetPage<Shop>(pageId));
        }

        [HttpPost]
        public ActionResult Edit(Shop shop)
        {
           
            if (ModelState.IsValid)
            {
                CH.Edit<Shop>(shop);
                var pageId = Pager6.Ins.GetPageId<Shop>(shop.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(shop);
        }


        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            CH.Delete<Shop>(id);
            return RedirectToAction("Index");
        }

        [HttpPost]
        public ActionResult Create(Shop shop)
        {
            if (ModelState.IsValid)
            {
                shop.UpdateTime = DateTime.Now;
                shop.UpdatedUser = HttpContext.User.Identity.Name;
                CH.Create<Shop>(shop);
                var pageId = Pager6.Ins.GetPageId<Shop>(shop.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(shop);
        }

        public ViewResult Details(int? id)
        {
            Shop shop = CH.GetDataById<Shop>(id);
            return View(shop);
        }

        public ActionResult Create()
        {
            return View();
        }



        public ActionResult Edit(int? id)
        {
            return View(CH.GetDataById<Shop>(id));
        }



        public ActionResult Delete(int? id)
        {
            Shop shop = CH.GetDataById<Shop>(id);
            return View(shop);
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }

}